package com.southwind.service.impl;

import com.southwind.entity.Employee;
import com.southwind.mapper.EmployeeMapper;
import com.southwind.service.EmployeeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.southwind.util.AesUtils;
import com.southwind.util.PageObject;
import com.southwind.vo.EmployeeVO;
import com.southwind.vo.OrdersVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yujun
 * @since 2024-11-30
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public PageObject list(PageObject pageObject, Employee employee) {
        Long index = (pageObject.getCurrent()-1)*pageObject.getSize();
        Long length = pageObject.getSize();
        List<EmployeeVO> list = this.employeeMapper.list(index,length,employee);
        PageObject result = new PageObject();
        result.setData(list);
        result.setSize(pageObject.getSize());
        result.setCurrent(pageObject.getCurrent());
        result.setTotal(this.employeeMapper.count(employee));
        return result;
    }

    @Override
    public boolean setStatus(Integer status, Integer id) {
        int setStatus = this.employeeMapper.setStatus(status, id);
        if(setStatus == 1) return true;
        return false;
    }

    @Override
    public boolean resetPassword(Integer id) {
        //加密处理
        String password = AesUtils.encryptStr("123456",AesUtils.SECRETKEY);
        int resetPassword = this.employeeMapper.resetPassword(password,id);
        if(resetPassword == 1) return true;
        return false;
    }
}
